package com.example.runningdemo.designModel.observer;

import lombok.Getter;

/**
 * @program: Running-Demo
 * @description: 具体观察者
 * @author: kangwei
 * @create: 2024-08-12 10:02
 **/
public class RealObserver extends Subject {
    @Getter
    private String state;

    /**
     * 设置状态值，并通知所有观察者
     *
     * @param state
     */
    public void setState(String state) {
        this.state = state;
        this.notifyAllObserver(state);
    }

    public static void main(String[] args) {
        RealObserver realObserver = new RealObserver();

        ObserverImpl observer1 = new ObserverImpl();
        ObserverImpl observer2 = new ObserverImpl();
        ObserverImpl observer3 = new ObserverImpl();

        realObserver.registerObserver(observer1);
        realObserver.registerObserver(observer2);
        realObserver.registerObserver(observer3);
        realObserver.setState("100");

        realObserver.deleteObserver(observer1);
        realObserver.setState("20");
    }
}
